package com.hot12345.server.DBConnection;

 
import java.io.File;
import java.util.Properties;
import java.io.FileInputStream;
import java.io.*;

public class DBConfigure {

	private static Properties property = null;

	private static Object lock = new Object();

	private static void loadAll() {
		if (property == null) {
			try {
				  
				java.net.URL url = Thread.currentThread()
						.getContextClassLoader().getResource(
				"config" + File.separator
					          + "pool-pool.properties");
			// File propertyFile = new File(url.getFile());
				 File propertyFile = new File("D:/www/search/index/bbs2/config/pool-pool.properties");
			//	System.out.println(propertyFile.getAbsolutePath()); 
				property = new Properties();     
				property.load(new FileInputStream(propertyFile));
			} catch (Exception ex) {
				  try {
					    String filepath=ClassLoader.getSystemResource("").getPath();
					     System.out.println(filepath);
					    File propertyFile = new File(filepath+"config" + File.separator
					          + "pool-pool.properties");
					     
					    property = new Properties();
					    
					     property.load(new FileInputStream(propertyFile));
					    } catch (Exception e) {
					     // TODO Auto-generated catch block
					     throw new RuntimeException("read pool-pool.properties faile!");
					    } 

			}

		}  
	}  

	public static Properties getLibMap() {
		if (property == null) {
			synchronized (lock) {
				if (property == null) {
					loadAll();
				}
			}
		}
		return property;
	}

	public static String getValue(String key) {
		return getLibMap().getProperty(key);
	}

}
